package network.TCPDome;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class Service {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(10086);
        Socket accept = serverSocket.accept();

        InputStream inputStream = accept.getInputStream();

        System.out.print("我是服务器端,我收到的客户端请求是:");
        byte[] bytes = new byte[1024];
        int len;
        while ((len = inputStream.read(bytes)) != -1) {
            System.out.println(new String(bytes,0,len));
        }

        BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(accept.getOutputStream()));
        bufferedWriter.write("我是服务器端，我已接收到消息");

        bufferedWriter.close();
        accept.close();
        serverSocket.close();
    }
}
